package com.stx.servlet;

import com.stx.bean.LoginUser;
import com.stx.mapper.LoginUserMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(urlPatterns = {"/addUser"})
public class AddUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String pass = req.getParameter("pass");
        String email = req.getParameter("email");
        String role = req.getParameter("role");
        String gender = req.getParameter("gender");
        String phone = req.getParameter("phone");
        LoginUser loginUser = new LoginUser(0,username, pass, email, role, gender,phone, null);
        try {
            Boolean addUser = LoginUserMapper.addUser(loginUser);
            resp.sendRedirect("/userlist");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }

}
